﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ERPStore.MockConnector
{
	public class SettingsService : ERPStore.Services.ISettingsService
	{
		public SettingsService()
		{
		}

		public ERPStore.Settings.WebSiteSettings CreateWebSiteSettings()
		{
			var webSiteSettings = new ERPStore.Settings.WebSiteSettings();
			var cryptoProvider = new System.Security.Cryptography.RC2CryptoServiceProvider();
			cryptoProvider.GenerateKey();
			cryptoProvider.GenerateIV();
			webSiteSettings.CryptoIV = cryptoProvider.IV;
			webSiteSettings.CryptoKey = cryptoProvider.Key;
			return webSiteSettings;
		}

		public ERPStore.Settings.WebSiteSettings GetWebSiteSettings()
		{
			var result = CreateWebSiteSettings();
			result.Contact.ContactEmail = "test@test.com";
			result.Contact.BCCEmail = "test@test.com";
			result.Contact.ContactEmailName = "test";
			result.Contact.ContactFaxNumber = "0102030405";
			result.Contact.ContactPhoneNumber = "0102030405";
			result.Contact.CorporateName = "TEST";
			result.Contact.DefaultAddress = new ERPStore.Models.Address()
			{
				City = "test",
				CorporateName = "TEST",
				CountryId = ERPStore.Models.Country.Default.Id,
				Id = 1,
				RecipientName = "TEST",
				Street = "Street",
				ZipCode = "12345",
			};
			result.Contact.EmailSender = "testsender@test.com";
			result.Contact.EmailSenderName = "testsender";

			// Internal Shipping
			var deliveryCountry = new ERPStore.Models.DeliveryCountry();
			deliveryCountry.AllowPartialDelivery = false;
			deliveryCountry.CountryId= ERPStore.Models.Country.Default.Id;
			deliveryCountry.MinimalFreeOfCarriageAmount = 50;
			deliveryCountry.MinimalOrderAmount = 0;
			deliveryCountry.ShippingFeeAmount = 5;
			deliveryCountry.TaxRate = 19.6;

			result.Shipping.DeliveryCountryList.Add(deliveryCountry);

			// External Shipping (CEE)
			var ceeDeliveryCountry = new ERPStore.Models.DeliveryCountry();
			ceeDeliveryCountry.AllowPartialDelivery = false;
			ceeDeliveryCountry.CountryId = ERPStore.Models.Country.ESP.Id;
			ceeDeliveryCountry.MinimalFreeOfCarriageAmount = 50;
			ceeDeliveryCountry.MinimalOrderAmount = 0;
			ceeDeliveryCountry.ShippingFeeAmount = 10;
			ceeDeliveryCountry.TaxRate = 0.0;

			result.Shipping.DeliveryCountryList.Add(ceeDeliveryCountry);

			// External Shipping 
			var externalDeliveryCountry = new ERPStore.Models.DeliveryCountry();
			externalDeliveryCountry.AllowPartialDelivery = false;
			externalDeliveryCountry.CountryId = ERPStore.Models.Country.USA.Id;
			externalDeliveryCountry.MinimalFreeOfCarriageAmount = 150;
			externalDeliveryCountry.MinimalOrderAmount = 50;
			externalDeliveryCountry.ShippingFeeAmount = 15;
			externalDeliveryCountry.TaxRate = 0.0;

			result.Shipping.DeliveryCountryList.Add(externalDeliveryCountry);

			result.Shipping.ConveyorIdList.Add(1);
			result.Shipping.DefaultConveyorId = 1;
			result.DefaultUrl = "www.test.com";
			result.ApplicationName = "MockConnector";

			return result;
		}

		public void SaveSiteSettings(ERPStore.Settings.WebSiteSettings settings)
		{
		}

	}
}
